<div class="layui-card layadmin-header">
    <div class="layui-breadcrumb" lay-filter="breadcrumb">
        <a lay-href="">主页</a>
        <a>结算</a>
        <a><cite>审核</cite></a>
    </div>
</div>
<style>
    table{
        text-align: center;
    }
    .leftT {
        text-align: left;
    }
</style>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-tab layui-tab-brief">
            <ul class="layui-tab-title">
                <li class="layui-this">审核</li>
            </ul>
            <div class="layui-tab-content">
                <table id="audit" class="layui-table"></table>
                <form class="layui-form" >
                    <div class="layui-form-item" >
                        <label class="layui-form-label">备注</label>
                        <div class="layui-input-block" style="width:40%">
                            <input type="text" name="remark" id="remTxt" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block" >
                            <button id="auditTg" lay-submit lay-filter="auditTg" class="layui-btn layui-btn-normal" data-val="2">审核通过</button><button id="auditFai" lay-submit lay-filter="auditFai" class="layui-btn layui-btn-danger" data-val="3">审核不通过</button><a lay-href="sett/audit/" class="layui-btn">返回</a>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<script>
        
    layui.use(['admin', 'table','util','element', 'form'], function(){
        var table = layui.table
        ,$ = layui.$
        ,form = layui.form
        ,admin = layui.admin
        ,element = layui.element;
        
        element.render('breadcrumb', 'breadcrumb');//渲染导航信息
        var router = layui.router();
        var creId = router.search.id;

        admin.req({
            type: 'get',
            url: layui.setter.baseUrl + '/sett/get',
            data: {
                id: creId,
            },
            error: function(err){
                layer.alert(err);
            },
            success: function(res){
                if(res.code == 0 && res.data != null){
                    var html = '';
                    html += `
                        <table>
                            <colgroup>
                                <col width="25%">
                                <col>
                                <col width="25%">
                                <col>
                            </colgroup>
                            <tbody>
                                <tr>
                                    <td>结算订单号</td>
                                    <td class="leftT">${res.data.settOrderId == null ? "" : res.data.settOrderId}</td>
                                    <td>结算日期</td>
                                    <td class="leftT">${ layui.util.toDateString(res.data.settDate, "yyyy-MM-dd") }</td>
                                </tr>
                                <tr>
                                    <td>结算商类型</td>
                                    <td class="leftT">${res.data.infoType==1?"代理商":res.data.infoType==2?"商户":""}</td>
                                    <td>结算商ID</td>
                                    <td class="leftT">${res.data.infoId}</td>
                                </tr>
                                <tr>
                                    <td>结算类型</td>
                                    <td class="leftT">${res.data.settType==1?"手工结算":res.data.settType==2?"自动结算":""}</td>
                                     <td>结算金额</td>
                                    <td class="leftT">${res.data.settAmount/100 }</td>
                                </tr>
                                <tr>
                                    <td>打款金额</td>
                                    <td class="leftT">${res.data.remitAmount/100}</td>
                                    <td>手续费</td>
                                    <td class="leftT">${res.data.settFee/100}</td>
                                </tr>
                                <tr>
                                    <td>账户属性</td>
                                    <td class="leftT">${res.data.accountAttr==0?"对私":res.data.accountAttr==1?"对公":""}</td>
                                    <td>账户类型</td>
                                    <td class="leftT">${res.data.accountType==1?"银行账户":res.data.accountType==2?"微信账户":res.data.accountType==3?"支付账户":""}</td>
                                </tr>
                                <tr>
                                    <td>开户行名称</td>
                                    <td class="leftT">${res.data.bankName}</td>
                                    <td>开户网点名称</td>
                                    <td class="leftT">${res.data.bankNetName}</td>
                                </tr>
                                <tr>
                                    <td>账户名</td>
                                    <td class="leftT">${res.data.accountName}</td>
                                    <td>账户号</td>
                                    <td class="leftT">${res.data.accountNo}</td>
                                </tr>
                                <tr>
                                    <td>开户行所在省</td>
                                    <td class="leftT">${res.data.province}</td>
                                    <td>开户行所在市</td>
                                    <td class="leftT">${res.data.city}</td>
                                </tr>
                                <tr>
                                    <td>结算状态</td>
                                    <td class="leftT">${res.data.settStatus == 1?"等待审核":res.data.settStatus == 2?"已审核":res.data.settStatus == 3?"审核不通过":res.data.settStatus == 4?"打款中":res.data.settStatus == 5?"打款成功":res.data.settStatus == 6?"打款失败":"非法结算状态"}</td>
                                    <td>创建时间</td>
                                    <td class="leftT">${ layui.util.toDateString(res.data.createTime) }</td>
                                </tr>
                                <tr>
                                    <td>操作人ID</td>
                                    <td class="leftT">${res.data.operatorId == null ? "" : res.data.operatorId}</td>
                                    <td>备注</td>
                                    <td class="leftT">${res.data.remark}</td>
                                </tr>
                            </tbody>
                        </table>
                    `
                    $('#audit').html(html);
                }else {
                    layer.alert('请求数据为空');
                }
            }
        });

        //当点击审核通过按钮时
        form.on('submit(auditTg)', function(data){
            // 在这个回调函数里面写ajax提交
            var curSt = $('#auditTg').data('val');
            admin.req({
                type: 'post',
                url: layui.setter.baseUrl + '/sett/audit',
                // data: "params=" + JSON.stringify(data.field),
                data: {
                    remark : data.field.remark,
                    status: curSt,
                    id:creId
                },
                error: function(err){
                    layer.alert(err,{title:'发起的请求失败'})
                },
                success: function(res){
                    if(res.code == 0){
                        layer.alert(res.msg ,function(index){
                            layer.close(index);
                            location.hash = '/sett/audit/';
                        })
                    }
                }
            })
            return false;//阻止跳转
        });



        form.on('submit(auditFai)', function(data){
            // 在这个回调函数里面写ajax提交
            var curSt = $('#auditFai').data('val');
            admin.req({
                type: 'post',
                url: layui.setter.baseUrl + '/sett/audit',
                // data: "params=" + JSON.stringify(data.field),
                data: {
                    remark : data.field.remark,
                    status: curSt,
                    id:creId
                },
                error: function(err){
                    layer.alert(err,{title:'发起的请求失败'})
                },
                success: function(res){
                    if(res.code == 0){
                        layer.alert(res.msg ,function(index){
                            layer.close(index);
                            location.hash = '/sett/audit/';
                        })
                    }
                }
            })
            return false;//阻止跳转
        });
        form.render();
     
    })

</script>